home *** CD-ROM | disk | FTP | other *** search
- Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
- From: floydb1@lib104.its.rpi.edu (Barry B Floyd)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: getch() equivalency help ...
- Date: 23 Jan 1996 09:41:24 -0500
- Organization: Rensselaer Polytechnic Institute, Troy, NY.
- Message-ID: <4e2s2k$6qj@lib104.its.rpi.edu>
- References: <4dpe6p$e4j@twin.wasatch.com> <4e11eh$l96@hacgate2.hac.com>
- NNTP-Posting-Host: lib104.its.rpi.edu
- X-newsreader: xrn 7.04-beta-11
-
-
- In article <4e11eh$l96@hacgate2.hac.com>, collins@thor.tu.hac.com (Ron Collins) writes:
- |> Richard Demanowski (rdemanow@wasatch.com) wrote:
- |> : I am looking for help with the following question/problem:
- |>
- |> : I want to have a function that does the same thing as getch() from
- |> : conio.h, but without needing to include conio.h.
- |> [snip]
- |>
- |> There is no portable way to do this. There are portable ways to read an
- |> entire line [fgets(stdin)], but if you need just one character, then
- |> you'll have to write OS specific code for each machine type.
- |>
- |> Probably the easiest thing to do would be to put curses on all machines
- |> (it exists for almost any OS you can think of, and can generally be found
- |> for free).
- |>
- |> -- Collins --
-
-
- I was battling with this problem as well, using iostreams. Apparently
- there isn't any way to do this with ">>", get( char *, LEN, DELIM ),
- read ( POINTER, LEN ), int get (), get ( char& C ).
-
- I was hopefull with the last two ( i.e. get a single character and
- put it in int/char& C. But everything is buffered.
-
- Is there a way to do this with the underlying/base class 'buf'?
-
- A related problem: after (temporarily) resigning myself to pressing
- the ENTER key after typing a character, I started playing with the
- ignore ( LEN, DELIM ) function. I want to ignore what ever "may"
- have been typed after the first character. Sometimes the buffer will
- be empty, sometimes not. I tried testing for EOF, and other 'fail'ures.
- I got expected results when inputting to a 'char' but had difficulties
- with 'char *'. The EOF flag seems to be set upon conditions I don't
- understand.
-
-
- Are there any code samples for using 'cin' functions? I have
- checked the FAQ and the usual WEB pages, but have found nothing
- to helpful. The most help has come from:
-
- GNU's g++/.../src/libio/iostream.info-1
-
- on our UNIX system.
-
- Ultimately, what I would like to have ( and have done in other
- languages ) is the following:
-
- int GetOption ( void )
- {
- String valid_chars = "somecharacters" ;
- int char_num = valid_chars.index ( cin.ASCII_or_scan_code () ) ;
-
- while ( char_num == -1 )
- valid_chars.index ( cin.ASCII_or_scan_code () ) ;
-
- switch char_num
- {
- case ...
- }
-
- return ( char_num ) ;
- }
-
-
- thanks
-
- barry
- --
- +--------------------------------------------------------------------+
- | Barry B. Floyd \\\ floydb1@rpi.edu |
- | RPI Alum. '84 '87 '88 \\\ |
- +--------------------------------------------------------------------+
-